<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //我们要注册一个会员，首先先新建两个单类
        //身份类
        var Identity = function(){
            this.status = '是会员身份'
        }
        //姓名类
        var Name =  function(name){
            //下面会形成闭包
            //对this进行baocun
            var self = this
            //console.log('this----',this)
            
            // //立即hanshu 
            // (function(name, self){
            //     self.wholename = name
            //     //对姓和名进行切割
            //     //对首次出现空格的地方进行检测
            //     if(name.indexOf(' ') > -1){
            //         self.firstname = name.slice(0,name,indexOf(' '))
            //         self.lastname = name.slice(indexOf(' '))
            //     }
            // })(name,self)
        }
        Name.prototype = function(){ 
                this.wholename = name
                //对姓和名进行切割
                //对首次出现空格的地方进行检测
                if(name.indexOf(' ') > -1){
                    this.firstname = name.slice(0,name,indexOf(' '))
                    this.lastname = name.slice(indexOf(' '))
                }
            
            return this.firstname +this.lastname
        }
         //会员种类
         var memberr = function(type){
            var that = this
            // (function(type,self){
            //     switch(type){
            //         case 1:
            //         case 10:
            //             that.member = '白银'
            //             break;
            //         case 11:
            //         case 20:
            //             that.member = '黄金'
            //             break;
            //         default:
            //             that.member = '荣耀'
            //     }
            // })(type,that)
            constructor = function(){
                switch(this.type){
                    case 1:
                    case 10:
                        this.member = '白银'
                        break;
                    case 11:
                    case 20:
                        this.member = '黄金'
                        break;
                    default:
                        this.member = '荣耀'
                }
                return this.member
            }
         }
        //  memberr.prototype = function(){
        //         switch(this.type){
        //             case 1:
        //             case 10:
        //                 this.member = '白银'
        //                 break;
        //             case 11:
        //             case 20:
        //                 this.member = '黄金'
        //                 break;
        //             default:
        //                 this.member = '荣耀'
        //         }
        //         return this.member
            
        //  }
         
         //人注册会员
         var Person = function (wholename,type){
            var identity = new Identity()
            identity.name = new Name(wholename)
            console.log()
            identity.member2 = new memberr(type)
            return identity
         }
         var person = new Person('weng jiaqi',45)
         console.log(person)
         console.log(person.member2)
         console.log(person.name)
    </script>
</body>
</html>